import { Body, Controller, Get, HttpCode, HttpStatus, Post, Request, UseGuards } from '@nestjs/common';
import { CategoryService } from './category.service';
import { CreateCategoryDto } from './dto/creater.dto';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

@ApiBearerAuth() // 需要token
// @Roles(RoleEnum.admin)
@ApiTags('分类管理')
@Controller({
	path: 'category',
	version: '1',
})
export class CategoryController {
	constructor(private readonly categoryService: CategoryService) {}

	@ApiBearerAuth()
	@UseGuards(AuthGuard('jwt'))
	@Post('/create')
	@HttpCode(HttpStatus.OK)
	create(@Request() request, @Body() createProfileDto: CreateCategoryDto) {
		return this.categoryService.create(createProfileDto, request.user.userId);
	}

	@Get('/getAllCategory')
	@HttpCode(HttpStatus.OK)
	getAll() {
		return this.categoryService.findAll();
	}
}
